package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.*;
import com.mall.user.IMemberService;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import java.util.Map;


@RestController
@RequestMapping("/shopping")
public class ShoppingController {

    @Reference(timeout = 3000, check = false)
    IHomeService iHomeService;
    @Reference(timeout = 3000, check = false)
    IContentService iContentService;
    @Reference(timeout = 3000, check = false)
    IProductCateService iproductCateService;


    IMemberService memberService;
    /**
     * 商品模块
     * 主页显示
     * @return
     */
    @Anoymous
    @GetMapping("/homepage")
    public ResponseData homepage() {
        HomePageResponse homePageResponse = iHomeService.homepage();
        if(homePageResponse.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(homePageResponse.getPanelContentItemDtos());
        }
        return new ResponseUtil<>().setErrorMsg(homePageResponse.getMsg());
    }

    /**
     * 导航栏显示
     * @return
     */
    @Anoymous
    @GetMapping("/navigation")
    public ResponseData navigation() {
        NavListResponse navListResponse = iContentService.queryNavList();
        if(navListResponse.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(navListResponse.getPannelContentDtos());
        }
        return new ResponseUtil<>().setErrorMsg(navListResponse.getMsg());
    }

    /**
     * 列举所有商品种类
     * @return
     */
    @Anoymous
    @GetMapping("/categories")
    public ResponseData listCategories(Map<String,String> map) {
        String sort = map.get("sort");
        AllProductCateRequest request = new AllProductCateRequest();
        request.setSort(sort);
        AllProductCateResponse allProductCate = iproductCateService.getAllProductCate(request);
        if(allProductCate.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(allProductCate.getProductCateDtoList());
        }
        return new ResponseUtil<>().setErrorMsg(allProductCate.getMsg());
    }

}
